'''
在单元格中放置控件
'''

import sys
from PyQt5.QtWidgets import *

class PlaceControlIncell(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle("在单元格中放置控件")
        self.resize(400,400)

        layout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])

        textItem = QTableWidgetItem('蓝洋')
        tableWidget.setItem(0, 0, textItem)
        combox = QComboBox()
        combox.addItem("男")
        combox.addItem("女")
        '''QSS'''
        combox.setStyleSheet('QComboBox{margin:3px}')
        tableWidget.setCellWidget(0, 1, combox)

        modifyBtn = QPushButton("modify")
        modifyBtn.setDown(True)
        modifyBtn.setStyleSheet('QPushButton{margin:3px}')
        tableWidget.setCellWidget(0, 2, modifyBtn)
        layout.addWidget(tableWidget)
        self.setLayout(layout)

if __name__ == '__main__':

    app = QApplication(sys.argv)

    ex = PlaceControlIncell()
    ex.show()
    sys.exit(app.exec_())